package com.xdcplus.web.handler;

import com.xdcplus.etl.schedule.annotation.Job;
import com.xdcplus.web.common.pojo.entity.DwWorkConf;
import com.xdcplus.web.handler.AbstractJobHandler;
import com.xdcplus.web.service.DmSortingService;
import com.xdcplus.web.service.DwWorkConfService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * 正背膜分选机数据清洗（5分钟）
 *
 * @author xukw
 * @date 2023/11/6 11:27
 */
@Slf4j
@Component
public class DmSortingHandler extends AbstractJobHandler {

    private final String HANDLER_NAME = "dmSortingHandler";

    @Resource
    private DmSortingService dmSortingService;
    @Resource
    private DwWorkConfService dwWorkConfService;
    @Job(HANDLER_NAME)
    @Override
    public void handler(String param) {
        DwWorkConf dwWorkConf = dwWorkConfService.queryDwWorkConfByEtlName(HANDLER_NAME);
        log.info("分选清洗开始...{}",dwWorkConf);
        LocalDateTime endDateTime = LocalDateTime.now().minusMinutes(
                dwWorkConf.getEtlQueryMinute());
        dmSortingService.execute(dwWorkConf);
        endJob(dwWorkConf);
        while (!dwWorkConf.getEtlEndTimestamp().toLocalDateTime().isAfter(endDateTime)) {
            try {
                log.info("分选清洗补偿...{}",dwWorkConf);
                dmSortingService.execute(dwWorkConf);
                endJob(dwWorkConf);
                Thread.sleep(500L);
            } catch (Exception e) {
                e.printStackTrace();
                break;
            }
        }
    }

    @Override
    public Object execute(DwWorkConf conf) {
        return null;
    }

}

